﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GlxRRSDB;
using GlxRRSReporter.DailyReporter;
using GlxRRSDB.Data;
using GlxRRSDB.Facades;
using GlxRRSDB.Utils;
using GlxRRSMain.Utils;


namespace GlxRRSMain.UserControls
{
    public partial class WeeklyReportByFilmControl : UserControl
    {
        public WeeklyReportByFilmControl()
        {
            InitializeComponent();
        }

        private void WeeklyReportByFilmControl_Load(object sender, EventArgs e)
        {
            // list cac phim dang chieu trong tuan
            dpickerD.Value = DateTime.Now;
            loadRangeDateTime();
        }

        private void loadRangeDateTime()
        {
            txtWeekNumber.Text = dpickerD.Value.CurrentWeekNumber().ToString();
            dpickerStart.Value = dpickerD.Value.StartOfWeek(DayOfWeek.Friday);
            dpickerEnd.Value = dpickerD.Value.EndOfWeek(DayOfWeek.Friday);

        }
        private void btnExport_Click(object sender, EventArgs e)
        {
            DateTime fromdate = dpickerD.Value;
            Dictionary<int, Dictionary<int, WeeklyReportData>> dictDetailFilm = new Dictionary<int, Dictionary<int, WeeklyReportData>>();
            //
            WeeklyReportFacade.getDetailFilmAdmissionWeek(fromdate, dictDetailFilm);
            WeeklyReportFacade.getDetailFilmBOWeek(fromdate, dictDetailFilm);
            // get current date report
            generateDailyReport(fromdate, dictDetailFilm);
        }
        private void generateDailyReport(DateTime d,
            Dictionary<int, Dictionary<int, WeeklyReportData>> dictDetailFilm)
        {
            WeeklyReporterByFilm.init(FileHelper.getWeeklyReportByFilmTemplate(), FileHelper.genWeeklyReportByFilmTemplateOut());
            WeeklyReporterByFilm.generateWeeklyReporterByFilm(d, dictDetailFilm);
        }

        private void dpickerD_ValueChanged(object sender, EventArgs e)
        {
            loadRangeDateTime();
        }
    }
}
